<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb>
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图 -->
        <el-card>
            <el-row>
                <el-col :span="8">
                    <!-- 搜索框 -->
                    <el-input placeholder="请输入内容" v-model="ordersInfo.query"
                     clearable @clear="getOrders">
                        <el-button slot="append" icon="el-icon-search" @click="getOrders"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 表单 -->
            <el-table :data="oredersList" style="width: 100%" border>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格" width="80px"></el-table-column>
                <el-table-column label="是否付款" width="80px">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.pay_status === '1'" type="success">已付款</el-tag>
                        <el-tag v-else type="danger">未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货" width="80px"></el-table-column>
                <el-table-column prop="create_time" label="下单时间" width="150px">
                    <template slot-scope="scope">{{scope.row.create_time | dateFormat}}</template>
                </el-table-column>
                <el-table-column label="操作" width="100px">
                    <template>
                        <el-button size="mini" type="primary" icon="el-icon-edit" circle @click="siteClick"></el-button>
                        <el-button size="mini" type="success" icon="el-icon-location-outline" circle @click="expressageClick"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination @size-change="handleSizeChange"  @current-change="handleCurrentChange"
             :current-page="this.ordersInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="this.ordersInfo.pagesize"
             layout="total, sizes, prev, pager, next, jumper" :total="this.total">
            </el-pagination>
        </el-card>
        <!-- 修改订单地址弹框 -->
        <el-dialog title="修改订单地址" :visible.sync="siteVisible" width="50%" @close="siteClose">
          <el-form :model="addSiteForm" :rules="addSiteRules" ref="addSiteRef" label-width="100px">
            <el-form-item label="省市区/县" prop="addSite1">
                <el-cascader v-model="addSiteForm.addSite1" :options="citydata"
                 :props="{ expandTrigger: 'hover' }">
                </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址" prop="addSite2">
                <el-input v-model="addSiteForm.addSite2"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="siteVisible = false">取 消</el-button>
            <el-button type="primary" @click="siteVisible = false">确 定</el-button>
          </span>
        </el-dialog>
        <!-- 物流弹框 -->
        <el-dialog title="物流详情" :visible.sync="expressageVisible" width="50%">
            <el-timeline>
                <el-timeline-item
                v-for="(activity, index) in addExpressageList"
                :key="index"
                :timestamp="activity.time">
                {{activity.context}}
                </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
                <el-button @click="expressageVisible = false">取 消</el-button>
                <el-button type="primary" @click="expressageVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import citydata from './citydata.js'
export default {
  data () {
    return {
      // 请求服务器订单数据参数
      ordersInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      // 服务器订单数据存储
      oredersList: [],
      // 修改订单地址弹框显示隐藏
      siteVisible: false,
      addSiteForm: {
        addSite1: [],
        addSite2: ''
      },
      addSiteRules: {
        addSite1: [{ required: true, message: '请填写省市区/县', trigger: 'blur' }],
        addSite2: [{ required: true, message: '请填写详细地址', trigger: 'blur' }]
      },
      // 省市区/县 级联内容
      citydata,
      // 物流弹框显示隐藏
      expressageVisible: false,
      // 存储物流信息
      addExpressageList: []
    }
  },
  created () {
    this.getOrders()
  },
  methods: {
    async getOrders () {
      const { data: res } = await this.$http.get('orders', { params: this.ordersInfo })
      console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error('订单列表获取失败')
      }
      this.$message.success('订单列表获取成功')
      this.oredersList = res.data.goods
      this.total = res.data.total
      console.log(this.oredersList)
      console.log(this.total)
    },
    // pageSize 改变时会触发
    handleSizeChange (newSize) {
      this.ordersInfo.pagesize = newSize
      this.getOrders()
    },
    // currentPage 改变时会触发
    handleCurrentChange (newPage) {
      this.ordersInfo.pagenum = newPage
      this.getOrders()
    },
    // 控制订单地址弹框方法
    siteClick () {
      this.siteVisible = true
    },
    // 重置弹框
    siteClose () {
      this.$refs.addSiteRef.resetFields()
    },
    // 物流功能
    async expressageClick () {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      console.log(res)

      if (res.meta.status !== 200) {
        return this.$message.error('获取物流信息失败')
      }
      this.$message.success('获取物流信息成功')
      this.addExpressageList = res.data
      console.log(this.addExpressageList)
      this.expressageVisible = true
    },
    // 搜索功能
    searchClcik () {

    }
  }
}
</script>

<style lang="less" scoped>

</style>
